# 类方法:

class A:

    num = 1


    def func(self):
        print('实例方法')

    @classmethod  # 类方法: 由类名直接调用的方法,他会自动的将类名传给cls
    def a_func(cls):
        # print(f'cls---> {cls}')
        # print(cls.num)
        # o = cls()
        # print(o)
        # print('这是类方法')
        print(cls)
# obj = A()
# obj.func()
# A.func(obj)
# print(A)
# A.a_func()
# obj.a_func()  # 对象也可以调用类方法,但是会自动将其从属于的类名传给cls




# 定义一个Student类,我要统计学生的个数.

# class Student:
#
#     num = 0
#
#     def __init__(self,name):
#         self.name = name
#         self.count()
#
#     @classmethod
#     def count(cls):
#         cls.num = cls.num + 1
#
#     @classmethod
#     def get_num(cls):
#         return cls.num
#
#
# ly = Student('李业')
# sq = Student('申强')
# sq1 = Student('申强')
# sq2 = Student('申强')
# sq3 = Student('申强')
# sq4 = Student('申强')
# print(Student.get_num())
#
#
# num = 1
# for i in range(4):
#     num += 1
#
# for i in range(6):
#     pass
#
#
# print(num)



# 静态方法: 不依赖于类,也不依赖于对象,他就是一个普通的函数放置于类中是结构更加清晰与合理.


# class A:
#
#
#     def func(self):
#         print(111)
#
#     @classmethod
#     def a_func(cls):
#         print(cls)
#
#     @staticmethod
#     def static_func(a,b,c):
#         print(f'{a}{b}{c}静态方法')
#
#
# def static_func(a,b,c):
#     print(f'{a}{b}{c}静态方法')
#
# # A.static_func()
# obj = A()
# obj.static_func(1,2,3)
#
#
#
# import time
#
# class TimeTest(object):
#     def __init__(self, hour, minute, second):
#         self.hour = hour
#         self.minute = minute
#         self.second = second
#
#     def get_year(self):
#         pass
#
#     def get_day(self):
#         pass
#
#     def last_year(self):
#         pass
#
#     @staticmethod
#     def showTime():
#         return time.strftime("%H:%M:%S", time.localtime())
#
# print(TimeTest.showTime())
# obj = TimeTest(1,20,60)
# obj.showTime()








